from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-10-01 14:13:00.027118
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 01, Oct, 2021
Time: 14:13:05
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.4576
Nobs: 431.000 HQIC: -46.9714
Log likelihood: 4780.53 FPE: 2.85101e-21
AIC: -47.3067 Det(Omega_mle): 2.31925e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.424578 0.091250 4.653 0.000
L1.Burgenland 0.105571 0.047242 2.235 0.025
L1.Kärnten -0.113636 0.023738 -4.787 0.000
L1.Niederösterreich 0.153608 0.101189 1.518 0.129
L1.Oberösterreich 0.110014 0.099454 1.106 0.269
L1.Salzburg 0.286000 0.049784 5.745 0.000
L1.Steiermark 0.035656 0.066146 0.539 0.590
L1.Tirol 0.106462 0.052299 2.036 0.042
L1.Vorarlberg -0.101697 0.046916 -2.168 0.030
L1.Wien -0.000310 0.090802 -0.003 0.997
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.015389 0.208458 0.074 0.941
L1.Burgenland -0.050104 0.107922 -0.464 0.642
L1.Kärnten 0.037472 0.054229 0.691 0.490
L1.Niederösterreich -0.212911 0.231165 -0.921 0.357
L1.Oberösterreich 0.495542 0.227201 2.181 0.029
L1.Salzburg 0.305731 0.113730 2.688 0.007
L1.Steiermark 0.105919 0.151109 0.701 0.483
L1.Tirol 0.312848 0.119477 2.618 0.009
L1.Vorarlberg 0.000143 0.107177 0.001 0.999
L1.Wien 0.002026 0.207435 0.010 0.992
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.243900 0.046303 5.267 0.000
L1.Burgenland 0.088528 0.023972 3.693 0.000
L1.Kärnten -0.003386 0.012046 -0.281 0.779
L1.Niederösterreich 0.207629 0.051347 4.044 0.000
L1.Oberösterreich 0.157102 0.050467 3.113 0.002
L1.Salzburg 0.039361 0.025262 1.558 0.119
L1.Steiermark 0.024315 0.033565 0.724 0.469
L1.Tirol 0.067022 0.026538 2.525 0.012
L1.Vorarlberg 0.061202 0.023807 2.571 0.010
L1.Wien 0.115712 0.046076 2.511 0.012
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187152 0.045185 4.142 0.000
L1.Burgenland 0.045842 0.023393 1.960 0.050
L1.Kärnten -0.006351 0.011755 -0.540 0.589
L1.Niederösterreich 0.141561 0.050106 2.825 0.005
L1.Oberösterreich 0.318420 0.049247 6.466 0.000
L1.Salzburg 0.100588 0.024652 4.080 0.000
L1.Steiermark 0.128784 0.032754 3.932 0.000
L1.Tirol 0.076871 0.025897 2.968 0.003
L1.Vorarlberg 0.055960 0.023231 2.409 0.016
L1.Wien -0.048839 0.044963 -1.086 0.277
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.206722 0.089584 2.308 0.021
L1.Burgenland -0.047655 0.046379 -1.028 0.304
L1.Kärnten -0.033375 0.023305 -1.432 0.152
L1.Niederösterreich 0.112681 0.099342 1.134 0.257
L1.Oberösterreich 0.170557 0.097639 1.747 0.081
L1.Salzburg 0.250912 0.048875 5.134 0.000
L1.Steiermark 0.077596 0.064939 1.195 0.232
L1.Tirol 0.123640 0.051345 2.408 0.016
L1.Vorarlberg 0.115320 0.046059 2.504 0.012
L1.Wien 0.027568 0.089144 0.309 0.757
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.036454 0.069207 0.527 0.598
L1.Burgenland 0.021041 0.035830 0.587 0.557
L1.Kärnten 0.054883 0.018004 3.048 0.002
L1.Niederösterreich 0.205365 0.076745 2.676 0.007
L1.Oberösterreich 0.340233 0.075429 4.511 0.000
L1.Salzburg 0.047053 0.037758 1.246 0.213
L1.Steiermark -0.007410 0.050167 -0.148 0.883
L1.Tirol 0.111150 0.039666 2.802 0.005
L1.Vorarlberg 0.069287 0.035582 1.947 0.052
L1.Wien 0.123207 0.068867 1.789 0.074
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197866 0.084702 2.336 0.019
L1.Burgenland 0.012779 0.043852 0.291 0.771
L1.Kärnten -0.056990 0.022035 -2.586 0.010
L1.Niederösterreich -0.125108 0.093928 -1.332 0.183
L1.Oberösterreich 0.194090 0.092318 2.102 0.036
L1.Salzburg 0.035515 0.046212 0.769 0.442
L1.Steiermark 0.285370 0.061400 4.648 0.000
L1.Tirol 0.489909 0.048547 10.092 0.000
L1.Vorarlberg 0.078538 0.043549 1.803 0.071
L1.Wien -0.109326 0.084286 -1.297 0.195
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158907 0.092451 1.719 0.086
L1.Burgenland -0.012774 0.047863 -0.267 0.790
L1.Kärnten 0.063564 0.024051 2.643 0.008
L1.Niederösterreich 0.195153 0.102521 1.904 0.057
L1.Oberösterreich -0.123241 0.100763 -1.223 0.221
L1.Salzburg 0.233500 0.050439 4.629 0.000
L1.Steiermark 0.149895 0.067016 2.237 0.025
L1.Tirol 0.048427 0.052988 0.914 0.361
L1.Vorarlberg 0.130301 0.047533 2.741 0.006
L1.Wien 0.158397 0.091997 1.722 0.085
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.480509 0.050240 9.564 0.000
L1.Burgenland -0.007916 0.026010 -0.304 0.761
L1.Kärnten -0.009680 0.013070 -0.741 0.459
L1.Niederösterreich 0.204774 0.055712 3.676 0.000
L1.Oberösterreich 0.252019 0.054757 4.603 0.000
L1.Salzburg 0.024025 0.027410 0.876 0.381
L1.Steiermark -0.021420 0.036418 -0.588 0.556
L1.Tirol 0.066844 0.028795 2.321 0.020
L1.Vorarlberg 0.060767 0.025830 2.353 0.019
L1.Wien -0.047541 0.049993 -0.951 0.342
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.021243 0.082826 0.140593 0.130302 0.045165 0.075320 -0.000472 0.187393
Kärnten 0.021243 1.000000 -0.043546 0.129356 0.048831 0.071939 0.452426 -0.090254 0.088944
Niederösterreich 0.082826 -0.043546 1.000000 0.283363 0.083506 0.268571 0.031149 0.136355 0.261876
Oberösterreich 0.140593 0.129356 0.283363 1.000000 0.176710 0.288579 0.157908 0.101681 0.135391
Salzburg 0.130302 0.048831 0.083506 0.176710 1.000000 0.125847 0.056102 0.107427 0.049461
Steiermark 0.045165 0.071939 0.268571 0.288579 0.125847 1.000000 0.132354 0.091625 -0.015768
Tirol 0.075320 0.452426 0.031149 0.157908 0.056102 0.132354 1.000000 0.046670 0.119806
Vorarlberg -0.000472 -0.090254 0.136355 0.101681 0.107427 0.091625 0.046670 1.000000 -0.047394
Wien 0.187393 0.088944 0.261876 0.135391 0.049461 -0.015768 0.119806 -0.047394 1.000000